﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserGroupAssign.ascx.cs"
    Inherits="Admin_MemberAdmin_Controls_UserGroupAssign" %>

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $("#<%=NoAssignGroupListBox.ClientID%>").dblclick(function() {
            assign();
        });

        $("#<%=AssignGroupListBox.ClientID %>").dblclick(function() {
            noAssign();
        });

        $("#assignButton").click(function() {
            assign();
        });
        $("#noAssignButton").click(function() {
            noAssign();
        });
    });

    function noAssign() {
        var noAssign = $("#<%=NoAssignGroupListBox.ClientID%>");
        var assign = $("#<%=AssignGroupListBox.ClientID %>");
        assignFrom(assign, noAssign);
    }
    function assign() {
        var noAssign = $("#<%=NoAssignGroupListBox.ClientID%>");
        var assign = $("#<%=AssignGroupListBox.ClientID %>");
        assignFrom(noAssign, assign);
    }


    function assignFrom(from, to) {
        from.children().each(function(i) {
            if (this.selected) {
                var assignValue = $(this).val();
                var assignText = $(this).text();
                from.children("option[value='" + assignValue + "']").remove();
                to.append("<option value='" + assignValue + "'>" + assignText + "</option>");
                if (to.attr("id") == "<%=AssignGroupListBox.ClientID %>") {
                    AddToHiddenBox(assignValue);

                }
                else {
                    RemoveFromHiddenBox(assignValue);
                }
            }
        });
    }

    function AddToHiddenBox(id) {
        var text = $("#<%=HiddenBoxAssignUserGroupId.ClientID %>");
        text.val(text.val() + "," + id);
    }
    function RemoveFromHiddenBox(id) {
        var text = $("#<%=HiddenBoxAssignUserGroupId.ClientID %>");
        var pos = text.val().replace("," + text.val());
        text.val(pos);
    }
    
</script>

<input type="hidden" id="HiddenBoxAssignUserGroupId" runat="server" />
<div style="height: 280px;">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <div style="float: left;">
                <div>
                    未分配用户组</div>
                <select id="NoAssignGroupListBox" runat="server" datatextfield="Name" datavaluefield="Id"
                    multiple="true" name="lbNoAssignUserGroup" size="10" style="width: 150px; height: 200px">
                </select>
            </div>
            <div style="float: left; width: 50px; margin: auto auto; text-align: center; vertical-align: middle;">
                <p>
                    <input type="button" id="assignButton" style="clear: both" class="ui-state-default ui-corner-all"
                        value=">>"></input>
                </p>
                <p>
                    <input type="button" id="noAssignButton" style="clear: both" class="ui-state-default ui-corner-all"
                        value="<<"></input></p>
            </div>
            <div style="float: left;">
                <div>
                    已分配用户组</div>
                <select id="AssignGroupListBox" runat="server" datatextfield="Name" datavaluefield="Id"
                    multiple="true" name="lbAssignUserGroup" style="width: 150px; height: 200px"
                    size="10">
                </select>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
